from django.template import loader, Context
from django.http import HttpResponse

from blog.models import BlogPost

def archive(request):
    posts = BlogPost.objects.all()  #从数据库获取所有的BlogPost对象
    t = loader.get_template("archive.html") #用loader从mysite/blog/templates/目录下找出名为archive.html的模板
    c = Context({'posts': posts})
    content = t.render(c)
    print(content)
    return HttpResponse(content)
